import requests
import json
from goods_feedback.config.setting import *
from goods_feedback.public.get_yaml import doYaml


def Login():
    rs=doYaml.get_data(os.path.join(data_path,'getlogin.yaml'))
    base_url='{0}{1}'.format(rs['url'],rs['path'])
    method=rs['method']
    payload=rs['login']
    headers=rs['header']

    try:
        re=requests.request(method,base_url,headers=headers,data=json.dumps(payload))
        if re.status_code==200:
            r=re.json()
            if r['code']==200:
                token=r['token']
            else:
                print('登录失败，请重新登录')
        #print('用户的token:%s' %(token))
        return token

    except Exception as e:
        print('错误的原因是:%s' %(e))

